package com.nzy.ssm.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.nzy.ssm.entity.Manage;
import com.nzy.ssm.util.Constants;

/**
 *  	后台用户登录拦截器
 * @author Administrator
 *
 */
public class UserLoginInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		HttpSession session = request.getSession();
		Manage manage = (Manage)session.getAttribute(Constants.MANAGE);
		//如果session中用户信息不为空，那么说明用户是登录状态，让该请求通过
		if (manage != null) {
			return true;
		}
		// 如果session 中用户信息为空，跳转到登录页
		response.sendRedirect(request.getContextPath()+"/manage/login");
		return false;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		
	}

}
